package com.neiquan.backstage.event.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.neiquan.backstage.common.util.ExtraSpringHibernateTemplate;
import com.neiquan.backstage.event.EventService;
import com.neiquan.backstage.pub.bsc.dao.po.Event;

@Service
public class EventServiceImp implements EventService{
	private static Class<?> poc = Event.class;
	@Autowired
	private ExtraSpringHibernateTemplate extraSpringHibernateTemplate;
	@Override
	public void add(Event entity) {
		// TODO Auto-generated method stub
		extraSpringHibernateTemplate.getHibernateTemplate().save(entity);
	}

	@Override
	public Event queryById(int id) {
		// TODO Auto-generated method stub
		return extraSpringHibernateTemplate.findFirstOneByPropEq(poc, "eventId", id);
	}

	@Override
	public void updata(Event entity) {
		// TODO Auto-generated method stub
		extraSpringHibernateTemplate.getHibernateTemplate().update(entity);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Event> queryAll() {
		// TODO Auto-generated method stub
		return (List<Event>) extraSpringHibernateTemplate.findAll(poc);
	}
	
	@Override
	public Event queryByName(String name) {
		return extraSpringHibernateTemplate.findFirstOneByPropEq(poc, "name", name);
	}

	@Override
	public List<Event> queryByMemberId(Integer memberId) {
		// TODO Auto-generated method stub
		return (List<Event>) extraSpringHibernateTemplate.getHibernateTemplate().find("From Event where memberId=?", memberId);
	}
}
